package com.ciwong.epaper.modules.epaper.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;


import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.epaper.bean.EpaperInfo;
import com.ciwong.epaper.modules.me.bean.ServiceDetail;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/8/3.
 */
public class AddBookPopupAdapter extends BaseAdapter {
    private Context mContext;

    private List<ServiceDetail> mList;

    public AddBookPopupAdapter(Context context, List<ServiceDetail> list) {
        this.mContext = context;
        this.mList = list;
    }

    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList == null && mList.isEmpty() ? null : mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_popup, null);
            holder.textView = (TextView) convertView.findViewById(R.id.item_pop_title);
            holder.imgView = (ImageView) convertView.findViewById(R.id.item_pop_img);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.textView.setText(mList.get(position).getServiceTypeName());

        if (mList.get(position).isSelect()) {
            holder.imgView.setVisibility(View.GONE);
        } else {
            holder.imgView.setVisibility(View.VISIBLE);
        }
        return convertView;
    }


    public static class ViewHolder {
        TextView textView;
        ImageView imgView;
    }

    public void addAll(List<ServiceDetail> infos) {

        if (this.mList == null) {
            this.mList = new ArrayList<ServiceDetail>();
        }
        if (infos != null) {

            for (ServiceDetail serviceDetail : infos) {
                if (!serviceDetail.isDeleted()) {
                    this.mList.add(serviceDetail);
                }
            }

            notifyDataSetChanged();

        }

    }

    public void clear() {
        if (this.mList != null) {
            this.mList.clear();
            notifyDataSetChanged();
        }
    }

    public List<ServiceDetail> getServiceDetails() {
        if (this.mList != null) {
            return this.mList;
        }
        return null;
    }
}
